@extends('{{ base_layout }}')

@section('{{ section_title|default('title') }}')
{{ model_class }} Management ::
@parent
@stop

{% if section_breadcrumb is defined %}
@section('{{ section_breadcrumb }}')
    <li><a href="{{ '{{ ' }} route('home') {{ '}}' }}"><i class="icon-home"></i> Dashboard</a><span class="divider"><i class="icon-angle-right"></i></span></li>
    <li class="active">{{ model_class }} list</li>
@stop
{% endif %}

@section('{{ section_content|default('content') }}')

<p>{{ '{{ ' }}link_to_route('{{ route_prefix }}.{{ model_name }}.create', 'Add new {{ model_class}}', null, array('class' => 'btn btn-info')) {{ '}}' }}</p>

{% if softdelete %}
    {{ '{{ ' }}link_to_route('{{ route_prefix }}.{{ model_name }}.index', 'Include Deleted {{ model_class}}', array('withTrashed' => 'true'), array('class' => 'btn btn-medium')) {{ '}}' }}
    {{ '{{ ' }}link_to_route('{{ route_prefix }}.{{ model_name }}.index', 'Show Only Deleted {{ model_class}}', array('onlyTrashed' => 'true'), array('class' => 'btn btn-medium')) {{ '}}' }}
{% endif %}

{{ '{{ ' }} ${{ model_name }}s->links() {{ '}}'}}

<table class="table table-bordered table-striped table-hover">
    <thead>
    <tr>
        {% for field in fields|keys %}
        <th>{{ field|replace('_', ' ')|title }}</th>
        {% endfor %}
        {%- if relations.belongsTo is defined %}
            {%- for related in relations.belongsTo %}
                <th>{{ related|replace('_', ' ')|title }}</th>
            {%- endfor %}
        {%- endif %}

        <th class="span2">Actions</th>
    </tr>
    </thead>
    <tbody>
    @foreach (${{ model_name }}s as ${{ model_name }})
    <tr>
{% for field in fields|keys %}
{% if field == 'id' %}
        <td>{{ '{{ ' }} link_to_route('{{ route_prefix }}.{{ model_name }}.show', ${{ model_name }}->{{ field }}, array(${{ model_name }}->id), array()) {{ '}}' }}</td>
{% else %}
        <td>{{ '{{ ' }} ${{ model_name }}->{{ field }} {{ '}}' }}</td>
{% endif %}
{% endfor %}

{% if relations.belongsTo is defined %}
{% for relation_name, related in relations.belongsTo %}
        <td>{{ '{{ ' }} ${{ model_name }}->{{ relation_name }}()->first() ? link_to_route('{{ route_prefix }}.{{ related }}.show', ${{ model_name }}->{{ relation_name }}()->first()->name, array('id' => ${{ model_name }}->{{ relation_name }}()->first()->id), array()) : 'NULL' {{ '}}' }}</td>
{% endfor %}
{% endif %}

        <td>
            <a href="{{ '{{ ' }} route('{{ route_prefix }}.{{ model_name }}.edit', ${{ model_name }}->id) {{ '}}' }}" class="btn btn-mini">Edit</a>
{% if softdelete %}
            @if ( ! is_null(${{ model_name }}->deleted_at))
            <a href="{{ '{{ ' }} route('{{ route_prefix }}.{{ model_name }}.restore', ${{ model_name }}->id) {{ '}}' }}" class="btn btn-mini btn-warning">Restore</a>
            @else
            <a href="{{ '{{ ' }} route('{{ route_prefix }}.{{ model_name }}.delete', ${{ model_name }}->id) {{ '}}' }}" class="btn btn-mini btn-danger">Delete</a>
            @endif
{% else %}
            <a href="{{ '{{ ' }} route('{{ route_prefix }}.{{ model_name }}.delete', ${{ model_name }}->id) {{ '}}' }}" class="btn btn-mini btn-danger">Delete</a>
{% endif %}
        </td>
    </tr>
    @endforeach
    </tbody>
</table>

{{ '{{ ' }} ${{ model_name }}s->links() {{ '}}'}}

@stop